package com.springboot.rigger.exception;

import com.springboot.rigger.common.ErrorCode;

public class BusinessException extends RuntimeException{
    private Integer code;
    private String msg;
    private Throwable cause;

    public BusinessException(){

    }

    public BusinessException(String msg) {
        super(msg);
        this.setCode(new BusinessException().getCode());
        this.setMsg(msg);
    }

    public BusinessException(ErrorCode businessCode) {
        super(businessCode.getMessage());
        this.setCode(businessCode.getCode());
        this.setMsg(businessCode.getMessage());
    }

    public BusinessException(String msg, Throwable e) {
        super(msg);
        this.setCode(new BusinessException().getCode());
        this.setMsg( msg);
        this.cause = e;
    }

    public BusinessException(ErrorCode businessCode, String msg) {
        super(msg);
        this.setCode(businessCode.getCode());
        this.setMsg(msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Throwable getCause() {
        return cause;
    }
}